
package bbchess.dialogs;

import bbchess.units.ChessPiece;

/**
 * CapturedPiecesDialog is the dialog that all captured pieces go. It presents
 * a quick view of how the game is progressing. Right now it's broken because it
 * expects the peices to draw themselves. But after the refactoring, it's the squares
 * that actually draw the pieces.
 * @author Tyler
 */
public class CapturedPiecesDialog extends ChessDialog {

    /** Creates new form DebugDialog */
    public CapturedPiecesDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal, false);
        initComponents();
    }

    @Override
    public void dispose() {
        super.dispose();
        super.getMainGui().setStatusMenuItemSelected(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        statusPanel = new javax.swing.JPanel();
        whiteCapturesPanel = new javax.swing.JPanel();
        blackCapturesPanel = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Captured Pieces");
        setResizable(false);

        whiteCapturesPanel.setBackground(new java.awt.Color(255, 255, 255, 70));
        whiteCapturesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("White's Captures"));
        whiteCapturesPanel.setFocusable(false);
        whiteCapturesPanel.setMaximumSize(new java.awt.Dimension(155, 90));
        whiteCapturesPanel.setMinimumSize(new java.awt.Dimension(155, 90));
        whiteCapturesPanel.setOpaque(false);
        whiteCapturesPanel.setPreferredSize(new java.awt.Dimension(155, 90));
        whiteCapturesPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));

        blackCapturesPanel.setBackground(new java.awt.Color(255, 255, 255, 70));
        blackCapturesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Black's Captures"));
        blackCapturesPanel.setMaximumSize(new java.awt.Dimension(155, 90));
        blackCapturesPanel.setMinimumSize(new java.awt.Dimension(155, 90));
        blackCapturesPanel.setOpaque(false);
        blackCapturesPanel.setPreferredSize(new java.awt.Dimension(155, 90));
        blackCapturesPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(whiteCapturesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
                    .addComponent(blackCapturesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE))
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(whiteCapturesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(blackCapturesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void addCapture(ChessPiece piece) {
        if (piece.getColor().equals("white")) {
            blackCapturesPanel.add(piece);
            piece.revalidate();
            repaint();
        }
        else {
            whiteCapturesPanel.add(piece);
            piece.revalidate();
            repaint();
        }
    }

    public void clearCapturedPieces() {
        whiteCapturesPanel.removeAll();
        blackCapturesPanel.removeAll();
        repaint();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel blackCapturesPanel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JPanel whiteCapturesPanel;
    // End of variables declaration//GEN-END:variables

}
